package com.xszx.servlet;

import com.xszx.beans.Goods;
import com.xszx.dao.GoodsDao;
import com.xszx.dao.impl.GoodsDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/IndexServlet")
public class IndexServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //向后台发送数据请求
        GoodsDao goodsDao = new GoodsDaoImpl();
        //促销
        List<Goods> goodsList1 = goodsDao.getGoodsIndex(1);
        //礼包
        List<Goods> goodsList2 = goodsDao.getGoodsIndex(0);

        //将数据发送至小程序页面
        req.getSession().setAttribute("goodsList1", goodsList1);
        req.getSession().setAttribute("goodsList2", goodsList2);

        req.getRequestDispatcher("my_likafu/index.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}